
 <?php
	//运行跨域
	  
	 header('Access-Control-Allow-Origin: *');
	 $conn=mysqli_connect("127.0.0.1","root","","vue_shop");
			//  处理一下请求失败
	if(!$conn)
	{
		die('不能连接数据库');
	}
    $username=$_GET['username'];
	$uesrpass=$_GET['userpass'];
	if(empty($username))
	{
		exit('禁止非法请求！');
	}
	 // 定义全局
	 $data=array();
	 $json='';
	class User 
	{
		public  $status;
		public  $nickName ;
		public  $unionId ;
		public  $city ;
		public  $avatarUrl ;
		public  $province ;
	}
	$sql="SELECT * FROM login where username='$username'";
	$result=mysqli_query($conn,$sql);
		if (!$result)
		{
			printf("Error: %s\n", mysqli_error($conn));
			exit();
			echo("查询错误");
		}
        $sql_login=mysqli_fetch_array($result);
        $sql_user=$sql_login['username'];
		$sql_pass=$sql_login['userpass'];
		if($uesrpass==$sql_pass)
		{	session_start();
			$user =new User();
			$user->status="ok";
			$user->nickName = $sql_login["nickName"];
			$user->unionId = $sql_login["unionId"];
			$user->city = $sql_login["city"];
			$user->avatarUrl = $sql_login["avatarUrl"];
			$user->province = $sql_login["province"];
			$data[]=$user;			
			$json = json_encode($data);//把数据转换为JSON数据.
			
			echo "{".'"user"'.":".$json."}";
        }
        else
        {
            $array = array("status" => "登录失败"); 
            echo json_encode($array);
        }
 ?>